/**
 * FileFind - ftp/shares indexing and search php engine
 * Module: agent-java
 * Description: Agent written in java language
 * Copyright (c) 2003-2010 Rage Steel, www.gt2.ru
 * ----------------------------------------------
 * $Id$
 */
package ru.ffind.agent.db;

import static ru.ffind.agent.db.DbTools.getRsByte;
import static ru.ffind.agent.db.DbTools.getRsInteger;
import static ru.ffind.agent.db.DbTools.getRsLong;
import static ru.ffind.agent.db.DbTools.getRsShort;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Date;

import org.springframework.jdbc.core.RowMapper;

import ru.ffind.common.model.Filename;

/**
 *
 * Implementation for filename stored in the database
 *
 * @author Rage Steel
 *
 */
public class DbFilename extends AbstractDbEntry implements Filename {

	private Integer fileId;
	private Integer dirId;
	private Short hostId;
	private Byte fileFlags;
	private Long fileSize;
	
	protected DbFilename(
			Integer fileId, Integer dirId, Short hostId,
			String name, Byte fileFlags, Long fileSize, 
			Date fileDatetime, Date appDate) {
		super(name, fileDatetime, appDate);
		this.fileId = fileId;
		this.dirId = dirId;
		this.hostId = hostId;
		this.fileFlags = fileFlags;
		this.fileSize = fileSize;
	}
	
	public final static RowMapper<DbFilename> ROW_MAPPER = new RowMapper<DbFilename>() {
		
		@Override
		public DbFilename mapRow(ResultSet rs, int rowNum) throws SQLException {
			return new DbFilename(getRsInteger(rs, "file_id"), getRsInteger(rs, "dir_id"), getRsShort(rs, "host_id"),
				rs.getString("file_name"), getRsByte(rs, "file_flags"), getRsLong(rs, "file_size"),
				rs.getTimestamp("file_datetime"), rs.getDate("app_date"));
		}
	};

	// Getters
	
	public Integer getFileId() {
		return fileId;
	}
	
	public Integer getDirId() {
		return dirId;
	}
	
	public Short getHostId() {
		return hostId;
	}
	
	public Byte getFileFlags() {
		return fileFlags;
	}
	
	// Setters
	
	public void setFileId(Integer fileId) {
		this.fileId = fileId;
	}
	
	public void setDirId(Integer dirId) {
		this.dirId = dirId;
	}
	
	public void setHostId(Short hostId) {
		this.hostId = hostId;
	}
	
	public void setFileFlags(Byte fileFlags) {
		this.fileFlags = fileFlags;
	}
	
	public void setFileSize(Long fileSize) {
		this.fileSize = fileSize;
	}
	
	/* (non-Javadoc)
	 * @see ru.ffind.agent.model.Filename#getFileSize()
	 */
	@Override
	public long getFileSize() {
		return fileSize;
	}

	/*
	@Override
	public boolean equals(Object obj) {
		return AbstractEntry.fileEquals(this, obj);
	}
	*/
}
